﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Hangjing.SQLServerDAL;
using Hangjing.Common;
using Hangjing.Model;

/// <summary>
/// 帐户管理
/// </summary>
public partial class qy_54tss_Admin_sysaccounts : System.Web.UI.Page
{
    Accounts dal = new Accounts();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            getItem();
        }
    }

    protected void getItem()
    {
        IList<AccountsInfo> list = dal.GetsubList();

        IList<AccountsInfo> first = list.Where(a => a.Parentid == 0).ToList();
        foreach (var item in first)
        {
            item.sublist = list.Where(a => a.Parentid == item.ID).ToList();
        }

        rtpNewsSortList.DataSource = first;
        rtpNewsSortList.DataBind();
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            if (dal.DelList(e.CommandArgument.ToString()) > 0)
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除成功！');init();");
                getItem();
            }
            else
            {
                AlertScript.RegScript(this, UpdatePanel1, "jtip('删除失败，请重试！');init();");
            }
        }
    }

    protected void rtpNewsSortList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string Id = e.CommandArgument.ToString();
        switch (e.CommandName)
        {
            case "del":
                if (dal.DelList(Id) > 0)
                {
                    AlertScript.RegScript(this.Page, this.UpdatePanel1, "alert('刪除成功','text:刪除成功!','250','150','true','1000','true','text');init();");

                    getItem();
                }
                else
                {
                    AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:删除失败!','250','150','true','1000','true','text');init();");
                    getItem();
                }
                break;
        }

    }


    protected void btSave_Click(object sender, EventArgs e)
    {
        AccountsInfo mm = new AccountsInfo();
        mm.Parentid = HjNetHelper.GetQueryInt("id", 0);
        mm.Status = 0;
        mm.isDel = 0;
        mm.classname = WebUtility.InputText(tbclassname.Text);
        mm.linkurl = "";
        mm.hovepic = "";
        mm.pic = "";
        mm.Depth = 1;
        mm.Priority = Convert.ToInt32(tbpri.Text);
        if (dal.Add(mm) > 0)
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('添加成功！');init();");
            tbclassname.Text = "";
            getItem();
        }
        else
        {
            AlertScript.RegScript(Page, UpdatePanel1, "jtip('添加失败，请重试！');init();");
        }

    }
}

